﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;
using System.Security.Permissions;

namespace Tencent.OA.App
{
    //[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class ScheduleServiceSection : ConfigurationSection
    {
        /// <summary>
        /// <para> 定义一个 ScheduleServiceSection 配置节的节点名。</para>
        /// </summary>
        internal const string ScheduleServiceSectionKey = "schedules";

        //private static ScheduleServiceSection m_instance;
        private static ConfigurationPropertyCollection m_properties = new ConfigurationPropertyCollection();
        private static readonly ConfigurationProperty m_propSchedules = new ConfigurationProperty(null, typeof(ScheduleServiceProviderElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);

        static ScheduleServiceSection()
        {
            m_properties.Add(m_propSchedules);
        }

        ///// <summary>
        ///// <para> 获取 ScheduleServiceSection 类的实例。</para>
        ///// </summary>
        ///// <returns></returns>
        //public static ScheduleServiceSection GetSection()
        //{
        //    if (m_instance == null)
        //    {
        //        // m_instance = ConfigurationManager.GetSection(TencentConfigurationSectionGroup.TencentConfigurationSectionGroupName + "/" + TencentConfigurationSectionKey) as TencentConfigurationSection;
        //        m_instance = TencentConfigurationSectionGroup.GetSection<ScheduleServiceSection>(ScheduleServiceSectionKey);
        //        if (m_instance == null)
        //            throw new ConfigurationErrorsException("The configuration section named '" + ScheduleServiceSectionKey + "' should be specified.");
        //    }
        //    return m_instance;
        //}

        /// <summary>
        /// <para> 获取配置中的调度任务集合。</para>
        /// </summary>
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public ScheduleServiceProviderElementCollection ScheduleServiceProviders
        {
            get { return (ScheduleServiceProviderElementCollection)base[m_propSchedules]; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return m_properties; }
        }

        ///// <summary>
        ///// <para> 获取或设置可应用于所有调度任务循环执行的间隔时间(分钟)。默认为5分钟。</para>
        ///// </summary>
        //[ConfigurationProperty("interval", DefaultValue = 5)]
        //public int Interval
        //{
        //    get { return (int)this["interval"]; }
        //    //set { this["interval"] = value; }
        //}
    }
}
